import 'dart:html';
//import 'dart:isolate';

void view() {
  var disknum = 0;
  query("#title_id").text = 'Tower Of Hanoi disk numbers = $disknum';
  var runbutton = query("#run");
  runbutton.onClick.listen((e){
    var sw = new Stopwatch()..start();
    disknum++;
    query("#title_id").text = 'Tower Of Hanoi disk numbers = $disknum';
    hanoi(disknum,'A','B','C');
    sw.stop();
    print('${sw.elapsedMilliseconds}ms.');
    //var li = new LIElement();
    //li.text = 'time used: ${sw.elapsedMilliseconds}ms.';
    //query("#sample_text_id").children.add(li);
    query("#sample_text_id").innerHtml += '<li>time used: ${sw.elapsedMilliseconds}ms.</li>';
  });
  var clearbutton = query("#clear");
    clearbutton.onClick.listen((e){
    disknum = 0;
    query("#title_id").text = 'Tower Of Hanoi disk numbers = $disknum';
    query("#sample_text_id").innerHtml = '';
  });
}

var count = 0;
void hanoi(n,x,y,z) {
  if (n == 1){
    count++;
    //var li = new LIElement();
    //li.text = '$count.move disk $n from $x to $z';
    //query("#sample_text_id").children.add(li); 
    query("#sample_text_id").innerHtml += '<li>$count.move disk $n from $x to $z</li>';
    //send_text(count,n,x,z);
  }
  else{
    hanoi(n-1,x,z,y);
    count++;
    //var li = new LIElement();
    //li.text = '$count.move disk $n from $x to $z';
    //query("#sample_text_id").children.add(li);
    query("#sample_text_id").innerHtml += '<li>$count.move disk $n from $x to $z</li>';
    //send_text(count,n,x,z);
    hanoi(n-1,y,x,z);
  }
}

/*class Message{
  var count,n,x,z;
  Message();
  setValue(count,n,x,z){
    this.count = count;
    this.n = n;
    this.x = x;
    this.z = z;
  }
}
var msg = new Message();
void send_text(count,n,x,z){
  msg.setValue(count, n, x, z);
  SendPort sendPort = spawnFunction(fetch_text);
  sendPort.call(msg).then((reply) {
    query("#sample_text_id").innerHtml += reply;
  });
}
fetch_text(){
  port.receive(( Message msg, SendPort reply) {
    reply.send('<li>${msg.count}.move disk ${msg.n} from ${msg.x} to ${msg.z}</li>');
  });
}*/
void main(){
  view();
}